<?php

$AUTH_ADMIN_USER 		= isset($AUTH_ADMIN_USER) ? $AUTH_ADMIN_USER : 'proteh';
$AUTH_ADMIN_PASSWORD 	= isset($AUTH_ADMIN_PASSWORD) ? $AUTH_ADMIN_PASSWORD : 'proteh';

if(!defined('ADMIN_PASSWORD'))
	define('ADMIN_PASSWORD', $AUTH_ADMIN_PASSWORD);
if(!defined('ADMIN_USERNAME'))
	define('ADMIN_USERNAME', $AUTH_ADMIN_USER);

$NEED_AUTHORISATION = (isset($_SERVER["HTTPS"]) && $_SERVER['HTTPS']=='on') ? 0 : 1;
if($NEED_AUTHORISATION) {
	if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
		$_SERVER['PHP_AUTH_USER'] != ADMIN_USERNAME ||	$_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD) {
		
		Header("WWW-Authenticate: Basic realm=\"Prijava\"");
		Header("HTTP/1.0 401 Unauthorized");
	
		echo 
<<<EOB
<html><body>
<h1>Neuspešna prijava!</h1>
<big>Pogrešno korisničko ime i/ili Lozinka!</big><br/>&nbsp;<br/>&nbsp;
<big><a href='{$_SERVER['REQUEST_URI']}'>Dalje...</a></big>
</body></html>
EOB;
		exit();
	}
	else {
		$AUTHENTICATED=1;
	}
}

?>